home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_2 / ir_samp < prev    next >
Internet Message Format  |  1995-03-31  |  16KB

  1. From: Steve VanDevender <stevev@grayback.uoregon.edu>
  2. Subject:  v03i019:  ir_samp - New remote control sampling programs v1.0, Part01/01
  3. Newsgroups: comp.sources.hp48
  4. Followup-To: comp.sys.hp48
  5. Approved: spell@seq.uncwil.edu
  6.  
  7. Checksum:  796012700 (verify with brik -cv)
  8. Submitted-by: Steve VanDevender <stevev@grayback.uoregon.edu>
  9. Posting-number: Volume 3, Issue 19
  10. Archive-name: ir_samp/part01
  11.  
  12. BEGIN_DOC ir.doc
  13. These programs embody a new way of performing infrared remote control
  14. sampling on the HP-48.  The previously distributed remote sampling
  15. programs have sampled IR input by continually reading the IR input and
  16. immediately writing it out to memory.  These programs use a different
  17. approach--they continually sample the IR input while incrementing a
  18. timing count, and only write information to memory when the IR state
  19. changes or the counter overflows.  This approach increases the effective
  20. sampling rate under many circumstances and greatly reduces the amount
  21. of memory needed to store samples.  I have also paid special attention
  22. to instruction timing to make sure that the timing characteristics of
  23. the sampling and playback routines are as nearly identical as possible;
  24. this has been a problem with some previous attempts at remote sampling.
  25.  
  26. One of my motivations for writing these programs was that the other
  27. IR samplers I tried wouldn't work at all with my VCR.  Both of these
  28. work with my VCR, although I have obtained mixed results using these
  29. programs with other kinds of remotes.  I am hoping that these programs
  30. will be more effective than previous attempts, and that the techniques
  31. I have used here can be improved upon by others.
  32.  
  33. There are two separate IR sampling systems included here.  The first,
  34. in irsamp.star, irplay.star, ir.asc, and ir.uue, were the first programs
  35. I developed that worked.  They store 3-nibble sample units--1 nibble for
  36. the current IR input state, and 2 nibbles for a repeat count.  The
  37. inner loop of the sampling and playback routines runs at about 25
  38. microseconds per loop iteration, and take about 40 microseconds to
  39. write out the sample data and re-enter the inner loop.  These routines
  40. will make samples of about 90 bytes that work with my VCR.  The second,
  41. in irsamp2.star, irplay2.star, ir2.asc, and ir2.uue, use a similar
  42. approach but instead have only a 1-nibble repeat count.  The inner loop
  43. of these routines runs at about 23 microseconds per iteration, but
  44. sample string are a little over twice as long, at 224 bytes for samples
  45. that work with my VCR.  Interestingly enough, though, Lutz Vieweg's
  46. RFP program will pack samples created by either set of routines to about
  47. the same length of 60 bytes.
  48.  
  49. This posting includes STAR assembler source for all machine-language
  50. routines and ASC and uuencoded directories containing the machine-
  51. language programs and user RPL wrapping functions that perform additional
  52. type checking and provide a cleaner interface to the provided routines.
  53.  
  54. The directory IR contains the 3-nibble sampling routines, and the directory
  55. IR2 contains the 2-nibble sampling routines.  IR contains the user RPL
  56. programs SAMPLE and PLAYBACK and the machine code objects IRSAMP and IRPLAY.
  57. IR2 contains SAMPLE2, PLAYBACK2, IRSAMP2, and IRPLAY2.  Similarly, irsamp.star
  58. and irplay.star are the STAR source for the 3-nibble sampling/playback 
  59. routines, while irsamp2.star and irplay2.star are the source for the 2-nibble
  60. routines.
  61.  
  62. The program SAMPLE (SAMPLE2) will take either a real number in level
  63. 1, which is used to generate a string of that length to receive the sample, 
  64. or a string which will be overwritten with sample data.  It calls the 
  65. machine-language program IRSAMP (IRSAMP2) which performs the sampling.
  66. IRSAMP checks for a string object in level 1, which must have SIZE > 1, and 
  67. aborts if it doesn't find one.  It then waits up to 15 seconds for IR input,
  68. (that is, for you to place your remote control next to the calculator and
  69. press the button for the remote function you want to sample) and aborts if 
  70. none is received in that time.  Otherwise it begins sampling and exits when 
  71. the end of the string in level 1 is reached.  I have found that holding an 
  72. IR remote too close to the calculator during sampling will often result in 
  73. ineffective samples.
  74.  
  75. The program PLAYBACK (PLAYBACK2) will take a string in level 1 and feed
  76. it to IRPLAY (IRPLAY2), then drop the string.  You can feed strings
  77. directly to IRPLAY if you wish, but they will be left on the stack
  78. (although this is a useful way to test samples without having to recover
  79. them with LASTARG).  You should only feed strings created with IRSAMP to
  80. PLAYBACK or IRPLAY.  It is possible to create strings which leave the
  81. HP-48 IR LED on for long periods of time, which drains the batteries and
  82. may cause hardware damage.  In any case, IRPLAY will turn the IR LED off
  83. before exiting.
  84.  
  85. Two of my friends who have tested these programs have reported that they
  86. have experienced crashes while using them, although one report did not
  87. appear to involve memory corruption or any other damage.  However, I
  88. do not guarantee these programs to be bug-free--they may cause crashes,
  89. memory corruption, or even hardware damage if used improperly, although
  90. I can also say that I have had no problems for over a week since I
  91. debugged the routines in the IR directory.  Neither are they guaranteed
  92. to work with any IR remote control, although I suspect they will have
  93. greater success than previous remote sampling programs.
  94.  
  95. I would like to thank Dave Marsh for his original IR sampling programs,
  96. which I have copied small parts of and which were my main source of
  97. technical information in writing these programs, and Jan Brittenson for
  98. his excellent STAR assembler and MLDL debugger which made writing and
  99. debugging these programs easy.
  100. END_DOC
  101.  
  102.  
  103. ----------
  104.  
  105.  
  106. BEGIN_SRC irsamp.star
  107. ;irsamp.star:  ML core of a learning remote control sampler using run-length
  108. ;encoding for samples.  This version uses a 2-nibble repeat count.
  109.  
  110. ;requires a string in stack level 1, and overwrites its contents with the
  111. ;sample data.
  112.  
  113.         header    `x'
  114.  
  115.         code
  116.  
  117.         move.a    @d1, a        ;put TOS pointer in a
  118.         call    save_regs    ;save RPL registers
  119.         call    #01115        ;disable interrupts
  120.         call    #01bbd        ;turn off display
  121.  
  122.         move.a    a, d1        ;put TOS obj pointer in d1
  123.         move.a    @d1, a        ;get obj prolog
  124.         move.p5    type_string, c    ;get string prolog
  125.         brne.a    c, a, bailout    ;if not a string prolog abort
  126.         add    5, d1        ;move past string prolog
  127.         move.a    @d1, c        ;get string length field
  128.         add    5, d1        ;d1 now points to string data
  129.         sub.a    5, c        ;subtract 5 to get length of chars
  130.  
  131.         move.a    c, b
  132. div3:        srb.a    c        ;divide c by 4
  133.         srb.a    c
  134.         add.a    c, b        ;add to b
  135.         brnz.a    c, div3        ;while c > 0
  136.         srb.a    b        ;divide b by 4, to get approx. c/3
  137.         srb.a    b        ;c.a is 0
  138.         inc.a    c        ;c.a is 1
  139.         brle.a    b, c, bailout    ;if b <= 1, no room for samples
  140.         dec.a    b        ;trust me, you need this
  141.  
  142.         move.5    #0011a, d0    ;have d0 point to IR LED input nib
  143.         clr.a    c
  144.         move.1    c, @d0        ;clear LED status
  145.         move.p5    #80000, c    ;move timeout count to c
  146.                     ;should last about 16 s
  147. wait:        dec.a    c        ;c is timeout counter
  148.         brcs    bailout        ;if we dec past 0, bail out
  149. checkled:    move.xs    @d0, a        ;otherwise, check IR LED input
  150.         brbc    8, a, wait    ;if no input, wait for it
  151.  
  152. sample:        clr.b    c        ;c.b is the repeat count
  153.         move.xs    a, c        ;copy current input state from a.xs
  154. samploop:    move.xs    @d0, a        ;get IR LED status
  155.         inc.x    c        ;increment repeat count
  156.         breq.xs    c, a, samploop    ;while c.xs is undisturbed, loop
  157.         move.3    c, @d1        ;write state and repeat count
  158.         add    3, d1        ;increment d1
  159.         dec.a    b        ;one less sample
  160.         brcc    sample        ;back for new sample
  161.         
  162. bailout:    call    #010e5        ;allow interrupts
  163.         call    #01b8f        ;turn on display
  164.         jump    rr_rplcont    ;back to RPL
  165.  
  166.         endcode
  167.  
  168. END_SRC irsamp.star
  169.  
  170. BEGIN_SRC irplay.star
  171. ;irplay.star:  ML core of playback program for learning remote control
  172.  
  173. ;requires a string in stack level 1 generated by irsamp
  174.  
  175.         header    `x'
  176.  
  177.         code
  178.  
  179.         move.a    @d1, a        ;put TOS obj pointer in a
  180.         call    save_regs    ;save RPL registers
  181.         call    #01115        ;disable interrupts
  182.         call    #01bbd        ;turn off display
  183.  
  184.         move.a    a, d1        ;put TOS obj pointer in d1
  185.         move.a    @d1, a        ;get obj prolog
  186.         move.p5    type_string, c    ;get string prolog
  187.         brne.a    c, a, bailout    ;if not a string prolog abort
  188.         add.a    5, d1        ;move past string prolog
  189.         move.a    @d1, c        ;get string length field
  190.         add.a    5, d1        ;d1 now points to string data
  191.         sub.a    5, c        ;subtract 5 for length of string chars
  192.  
  193.         move.a    c, b
  194. div3:        srb.a    c        ;divide c by 4
  195.         srb.a    c
  196.         add.a    c, b        ;add to b
  197.         brnz.a    c, div3        ;while c > 0
  198.         srb.a    b        ;divide b by 4, to get approx. c/3
  199.         srb.a    b        ;c.a is 0
  200.         inc.a    c        ;c.a is 1
  201.         brle.a    b, c, bailout    ;if b <= 1, no room for samples
  202.         dec.a    b        ;trust me, you need this
  203.  
  204.         move.5    #0011c, d0    ;d0 points to IR LED output
  205. playback:    move.3    @d1, c        ;get a sample
  206.         add    3, d1
  207.         dec.x    c        ;decrement repeat count
  208.         move.xs    c, a        ;copy IR state to a
  209. playloop:    move.xs    c, @d0        ;output current LED state
  210.         dec.x    c        ;decrement counter
  211.         breq.xs    c, a, playloop    ;timing only-branch never taken
  212.         dec.a    b        ;one less sample
  213.         brcc    playback    ;repeat until out of samples
  214.  
  215.         clr.a    c        ;clear c.0
  216.         move.1    c, @d0        ;clear LED output
  217.  
  218. bailout:    call    #010e5        ;allow interrupts
  219.         call    #01b8f        ;turn on display
  220.         jump    rr_rplcont    ;back to RPL
  221.  
  222.         endcode
  223.  
  224. END_SRC irplay.star
  225.  
  226. BEGIN_SRC irsamp2.star
  227. ;irsamp2.star:  ML core of a learning remote control sampler using run-length
  228. ;encoding for samples.  This version uses a one-nibble repeat count.
  229.  
  230. ;requires a string in stack level 1, and overwrites its contents with the
  231. ;sample data.
  232.  
  233.         header    `x'
  234.  
  235.         code
  236.  
  237.         move.a    @d1, a        ;put TOS pointer in a
  238.         call    save_regs    ;save RPL registers
  239.         call    #01115        ;disable interrupts
  240.         call    #01bbd        ;turn off display
  241.  
  242.         move.a    a, d1        ;put TOS obj pointer in d1
  243.         move.a    @d1, a        ;get obj prolog
  244.         move.p5    type_string, c    ;get string prolog
  245.         brne.a    c, a, bailout    ;if not a string prolog abort
  246.         add    5, d1        ;move past string prolog
  247.         move.a    @d1, c        ;get string length field
  248.         add    5, d1        ;d1 now points to string data
  249.         sub.a    5, c        ;subtract 5 to get length of chars
  250.  
  251.         move.a    c, b
  252.         srb.a    b        ;divide string length by two
  253.         clr.a    c
  254.         inc.a    c        ;set c.a to 1
  255.         brle.a    b, c, bailout    ;if b <= 1, no room for samples
  256.         dec.a    b        ;trust me, you need this
  257.  
  258.         move.5    #0011a, d0    ;have d0 point to IR LED input nib
  259.         move.p5    #80000, c    ;move timeout count to c
  260.         move    1, p
  261.         clr.a    a
  262.         move.b    a, @d0        ;clear IR status nibble
  263. wait:        dec.a    c        ;c is timeout counter
  264.         brcs    bailout        ;if we dec past 0, bail out
  265.         move.b    @d0, a        ;otherwise, check IR LED input
  266.         brbc    4, a, wait    ;if no input, wait for it
  267.  
  268. sample:        clr.b    c        ;c.0 is the repeat count
  269.         move.p    a, c        ;copy current input state from a.1
  270. samploop:    move.b    @d0, a        ;get IR LED status
  271.         inc.b    c        ;increment repeat count
  272.         breq.p    c, a, samploop    ;while c.1 is undisturbed, loop
  273.         move.b    c, @d1        ;write state and repeat count
  274.         add    2, d1        ;increment d1
  275.         dec.a    b        ;one less sample
  276.         brcc    sample        ;back for new sample
  277.         
  278. bailout:    move    0, p
  279.         call    #010e5        ;allow interrupts
  280.         call    #01b8f        ;turn on display
  281.         jump    rr_rplcont    ;back to RPL
  282.  
  283.         endcode
  284.  
  285. END_SRC irsamp2.star
  286.  
  287. BEGIN_SRC irplay2.star
  288. ;irplay2.star:  ML core of playback program for learning remote control
  289.  
  290. ;requires a string in stack level 1 generated by irsamp2
  291.  
  292.         header    `x'
  293.  
  294.         code
  295.  
  296.         move.a    @d1, a        ;put TOS obj pointer in a
  297.         call    save_regs    ;save RPL registers
  298.         call    #01115        ;disable interrupts
  299.         call    #01bbd        ;turn off display
  300.  
  301.         move.a    a, d1        ;put TOS obj pointer in d1
  302.         move.a    @d1, a        ;get obj prolog
  303.         move.p5    type_string, c    ;get string prolog
  304.         brne.a    c, a, bailout    ;if not a string prolog abort
  305.         add.a    5, d1        ;move past string prolog
  306.         move.a    @d1, c        ;get string length field
  307.         add.a    5, d1        ;d1 now points to string data
  308.         sub.a    5, c        ;subtract 5 for length of string chars
  309.  
  310.         move.a    c, b
  311.         srb.a    b        ;divide string length by two
  312.         clr.a    c
  313.         inc.a    c        ;set c.a to 1
  314.         brle.a    b, c, bailout    ;if b <= 1, no room for samples
  315.         dec.a    b        ;trust me, you need this
  316.  
  317.         move.5    #0011b, d0    ;d0 points to IR LED output - 1
  318.         clr.a    a
  319.         move    1, p
  320. playback:    move.b    @d1, c        ;get a sample
  321.         add    2, d1
  322.         dec.b    c        ;predecrement c
  323.         move.p    c, a        ;copy IR state to a
  324. playloop:    move.b    a, @d0        ;output current LED state
  325.         dec.x    c        ;decrement counter
  326.         breq.p    c, a, playloop    ;while c.1 is unchanged, loop
  327.         dec.a    b        ;one less sample
  328.         brcc    playback    ;repeat until out of samples
  329.         move    0, p
  330.  
  331.         clr.a    c        ;clear c.0
  332.         move.b    c, @d0        ;clear LED output
  333.  
  334. bailout:    call    #010e5        ;allow interrupts
  335.         call    #01b8f        ;turn on display
  336.         jump    rr_rplcont    ;back to RPL
  337.  
  338.         endcode
  339.  
  340. END_SRC irplay2.star
  341.  
  342. BEGIN_ASC ir.asc
  343. %%HP: T(3)A(R)F(.);
  344. "69A20FF7C32000000060942505C4149560CCD204A0001438FB97608F511108FD
  345. BB1013114334C2A208A626174147174818FA4D5819F2819F2C18AE1F819F1819
  346. F1E68BDF21BC1100CD15F2172A3EAAA1542A3E9226FCD54ED215C08F5E0108FF
  347. 8B108D341509B0006094253514D40560CCD20BB0001438FB97608F511108FDBB
  348. 1013114334C2A208A697174147174818FA4D5819F2819F2C18AE1F819F1819F1
  349. E68BD641BA1100D215C03400008CE4D21522808682FCDAE2AA61522B369226F1
  350. 5D2172CD54E8F5E0108FF8B108D341500D0008005C41495241434B480D9D20E1
  351. 6323CE2278BF168BC1ED2A2D9AE1AFE22D9D20C2A203200035472796E6760256
  352. 87075636475646933A1B21305DF2284E2060942505C414958DBF193632B2130A
  353. 9000603514D405C45460D9D20E1632D8732D9D2078BF168BC14B2A2279E18A73
  354. 2D9D20E4A20510007DC8100000000000E25A1E4A20510006765400000000000E
  355. 25A1B21305DF2278BF168BC1ED2A2D9AE18A732D9D20C2A2013000255616C602
  356. F6270235472796E676C20207C656163756933A1B21305DF22B21305DF2284E20
  357. 6094253514D40593632B2130BF43"
  358. END_ASC ir.asc
  359.  
  360. BYTES: #34FBh 434.5
  361.  
  362. BEGIN_UU ir.uue
  363. begin 644 ir3
  364. M2%!(4#0X+466*O!_/`(````&25)03$%9!LPM0`H`08._>0;X%1&`W[L!,1$T
  365. M0RPJ@&IB<11T<82!K]2%D2\8^<*!ZO$8^8&1'VZX_1++$0#<42]QHN.J&D6B
  366. MXREBSUWD+5$,^.40@/^X`=A#49`+``9)4E-!35`&S"VP"P!!@[]Y!O@5$8#?
  367. MNP$Q$31#+"J`:GEQ%'1QA(&OU(61+QCYPH'J\1CY@9$?;KAM%*L1`"U1#$,`
  368. M`,A.+5$B"&@HSZTNJA8ELF,I8A_5$B?<18Y?#@'XCQN`/10%T`"``,44E"44
  369. M-+2$T-D"'C8R["*'^V&X'-ZBTJD>^B[2V0(L*C`"`%-T<FEN9R!E>'!E8W1E
  370. M9#FCL1(#U2^"Y`(&25)03$%9V/N18R,K,:`)``9304U03$4&G2W@82.--]+9
  371. M`H?[8;@<M*(BEQZH-]+9`DXJ4`$`UXP!```````NI>&D`A4`8&=%``````#@
  372. M4AHK,5#](H?[8;@<WJ+2J1ZH-]+9`BPJ$`,`4F5A;"!O<B!3=')I;F<L('!L
  373. ?96%S93FCL1(#U2^R$@/5+X+D`@9)4E-!35`Y-K(2`P``
  374. `
  375. end
  376. END_UU ir.uue
  377.  
  378. BEGIN_ASC ir2.asc
  379. %%HP: T(3)A(R)F(.);
  380. "69A20FF7F12000000070942505C414952370CCD20390001438FB97608F511108
  381. FDBB1013114334C2A208A615174147174818FA4D5819F1D2E68BD23CD1BB1100
  382. D02114F171A6EA8A148A3E9027FCD56E20D214C8F5E0108FF8B108D34150AA00
  383. 07094253514D4052370CCD207A0001438FB97608F511108FDBB1013114334C2A
  384. 208A636174147174818FA4D5819F1D2E68BD44CD1BA1100340000821D0148CE4
  385. 8214A808643FAE2A8614AB669027F14D171CD56E208F5E0108FF8B108D34150E
  386. B0009005C41495241434B42390D9D20E16323CE2278BF168BC1ED2A2D9AE1AFE
  387. 22D9D20C2A203200035472796E676025687075636475646933A1B21305DF2284
  388. E2070942505C41495238DBF193632B2130E9000703514D405C4542370D9D20E1
  389. 632D8732D9D2078BF168BC14B2A2279E18A732D9D20E4A20510007DC81000000
  390. 00000E25A1E4A20510006765400000000000E25A1B21305DF2278BF168BC1ED2
  391. A2D9AE18A732D9D20C2A2013000255616C602F6270235472796E676C20207C65
  392. 6163756933A1B21305DF22B21305DF2284E207094253514D4052393632B21302
  393. BCE"
  394. END_ASC ir2.asc
  395.  
  396. BYTES: #ECB2h 423
  397.  
  398. BEGIN_UU ir2.uue
  399. begin 644 ir2
  400. M2%!(4#0X+466*O!_'P(````'25)03$%9,@?,+3`)`$&#OWD&^!41@-^[`3$1
  401. M-$,L*H!J47$4='&$@:_4A9$?+6ZX+<,=NQ$`#1)!'Q=JKJA!J.,)<L]=Y@(M
  402. M08Q?#@'XCQN`/10%J@!PD"0U%=0$)7/`W`*G`!`T^)MG@%\1`?B]&Q`303/$
  403. MH@*H-A9'01='&/A*71CYT>*&VT3<L1H!,`0`@!(-0<A.*$&*@$;SZJ)H0;IF
  404. M"7(?U''!7>8"^.40@/^X`=A#4>`+``E03$%90D%#2S()G2W@82/#+G*X'X;+
  405. MX2TJG>JA[R*=+<"B`B,`,$4GE^9V!E*&!U<V1E=&EC,:*S%0_2)(+G"0)`7%
  406. M%)0E@[T?.3:R$@.>`'`P%=0$Q50D<]#9`AXVTG@CG2UPN!^&RT$K*G+I@7HC
  407. MG2W@I`(5`'#-&```````X%(:3BI0`0!V5@0``````"ZEL1(#U2]RN!^&R^$M
  408. M*IWJ@7HCG2W`H@(Q`"!5%L8&\B8',D4GE^9VQ@("QU86-E>6,QHK,5#](BLQ
  409. 34/TB2"YPD"0U%=0$)9-C(RLQ````
  410. `
  411. end
  412. END_UU ir2.uue
  413.  
  414.